// JavaScript Document
/*var type_arr = {
	1 : { 'function_name' : 'insert_Slogan_Slider' },
	2 : { 'function_name' : 'insert_Image_Slider' }
};*/
function addRow( key ) {
	var postData = {
		url : 'insert_Slider', 
		key : key
	};
	$.ajax({
		type: "POST",
		url: "<?php echo TEMPLATE_URL; ?>/libs/actions.php",
		data: postData,
		cache: false,
		success: function(data){
			if( key == 2 ) {
				var htmlPlus = '<td id="adv3_'+ data +'"><input type="text" id="_adv3_'+ data +'" onclick="uploadGallery(\'_adv3_'+ data +'\')" style="width: 400px;" /></td>';
			} else {
				var htmlPlus = '<td id="adv1_'+ data +'"><input type="text" id="_adv1_'+ data +'" style="width: 400px;" /></td>';
			}
			var htmlAddNew = htmlPlus +
				'<td id="adv4_'+ data +'"><input type="text" id="_adv4_'+ data +'" placeholder="http://" style="width: 200px;" /></td>'+
				'<td id="adv2_'+ data +'"><a href="javascript:;" onclick="saveRow(\''+ key +'\', '+ data +')"><img src="<?php echo FOLDER_IMG; ?>/icon_sync.gif" alt="" /></a></td>'+
				'<td><a href="javascript:;" onclick="delRow(\''+ key +'\', '+ data +');"><img src="<?php echo FOLDER_IMG; ?>/icon_delete.gif" alt="" /></a></td>';
			$('table.tblDict tr:eq(0)').after('<tr id="dbAdv_'+ data +'" align="center">'+ htmlAddNew +'</tr>').hide().fadeIn('slow');
		}
	});
	return false;
}
function editRow( key, ID ) {
	if( key == 2 ) {
		$('#adv3_'+ ID).html('<input type="text" id="_adv3_'+ ID +'" value="'+ $('#adv31_'+ ID).attr('href') + '" onclick="uploadGallery(\'_adv3_'+ ID +'\')" style="width: 400px;" />');
	} else {
		$('#adv1_'+ ID).html('<input type="text" id="_adv1_'+ ID +'" value="'+ $('#adv1_'+ ID).text().replace(/"/g, '&quot;') + '" style="width: 400px;" />');
	}
	$('#adv4_'+ ID).html('<input type="text" id="_adv4_'+ ID +'" value="'+ $('#adv41_'+ ID).attr('href') + '" placeholder="http://" style="width: 200px;" />');
	$('#adv2_'+ ID).html('<a href="javascript:;" onclick="saveRow('+ key +', '+ ID +')"><img src="<?php echo FOLDER_IMG; ?>/icon_sync.gif" alt="" /></a>');
	return false;
}
function saveRow( key, ID ) {
	var title	= '';
	var image	= '';
	if( key == 2 )
		image	= $('#_adv3_'+ ID).val();
	else
		title	= $('#_adv1_'+ ID).val();
	var href	= $('#_adv4_'+ ID).val();

	var postData	= {
		url	: 	'save_Slider', 
		key	:	key,
		ID	: 	ID, 
		name: 	title,
		img	: 	image,
		href:	href
	};
	
	$.ajax({
		type: "POST",
		url: "<?php echo TEMPLATE_URL; ?>/libs/actions.php",
		data: postData,
		cache: false,
		success: function(data){
			if( key == 2 ) {
				var imgsrc = ''
				if(image){ 
					imgsrc = '<?php echo HOME_URL; ?>/timthumb.php?src='+ image +'&w=152&h=154&q=100';
				}
				$('#adv3_'+ ID).html('<a id="adv31_'+ ID +'" href="'+ image +'" target="_blank"><img src="'+ imgsrc +'" height="154" alt="" /></a>');
			} else {
				$('#adv1_'+ ID).html(title);
			}
			$('#adv4_'+ ID).html('<a id="adv41_'+ ID +'" href="'+ href +'" target="_blank">'+ href +'</a>');
			$('#adv2_'+ ID).html('<a href="javascript:;" onclick="editRow('+ key +', '+ ID +')"><img src="<?php echo FOLDER_IMG; ?>/icon_edit.gif" alt="" /></a>');
		}
	});
	return false;
}
function delRow( key, ID ) {
	var postData = {
		url : 'delete_Slider', 
		key : key,
		ID	: ID
	};
	$.ajax({
		type: "POST",
		url: "<?php echo TEMPLATE_URL; ?>/libs/actions.php",
		data: postData,
		cache: false,
		success: function(data){
			$('#dbAdv_'+ ID).remove();
		}
	});
	return false;
}